package com.ktgj.flight.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.flight.domain.ScreeningKey;
import com.ktgj.flight.service.IScreeningKeyService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 短信猫关键字过滤Controller
 * 
 * @author ruoyi
 * @date 2021-08-30
 */
@ControllerAdvice
@RestController
@RequestMapping("/key")
public class ScreeningKeyController extends BaseController
{
    @Autowired
    private IScreeningKeyService screeningKeyService;

    /**
     * 查询短信猫关键字过滤列表
     */
    @PreAuthorize(hasPermi = "flight:key:list")
    @GetMapping("/list")
    public TableDataInfo list(ScreeningKey screeningKey)
    {
        startPage();
        List<ScreeningKey> list = screeningKeyService.selectScreeningKeyList(screeningKey);
        return getDataTable(list);
    }

    /**
     * 导出短信猫关键字过滤列表
     */
    @PreAuthorize(hasPermi = "flight:key:export")
    @Log(title = "短信猫关键字过滤", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScreeningKey screeningKey) throws IOException
    {
        List<ScreeningKey> list = screeningKeyService.selectScreeningKeyList(screeningKey);
        ExcelUtil<ScreeningKey> util = new ExcelUtil<ScreeningKey>(ScreeningKey.class);
        util.exportExcel(response, list, "短信猫关键字过滤数据");
    }

    /**
     * 获取短信猫关键字过滤详细信息
     */
    @PreAuthorize(hasPermi = "flight:key:query")
    @GetMapping(value = "/{pkid}")
    public AjaxResult getInfo(@PathVariable("pkid") Long pkid)
    {
        return AjaxResult.success(screeningKeyService.selectScreeningKeyById(pkid));
    }

    /**
     * 新增短信猫关键字过滤
     */
    @PreAuthorize(hasPermi = "flight:key:add")
    @Log(title = "短信猫关键字过滤", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScreeningKey screeningKey)
    {
        return toAjax(screeningKeyService.insertScreeningKey(screeningKey));
    }

    /**
     * 修改短信猫关键字过滤
     */
    @PreAuthorize(hasPermi = "flight:key:edit")
    @Log(title = "短信猫关键字过滤", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScreeningKey screeningKey)
    {
        return toAjax(screeningKeyService.updateScreeningKey(screeningKey));
    }

    /**
     * 删除短信猫关键字过滤
     */
    @PreAuthorize(hasPermi = "flight:key:remove")
    @Log(title = "短信猫关键字过滤", businessType = BusinessType.DELETE)
	@DeleteMapping("/{pkids}")
    public AjaxResult remove(@PathVariable Long[] pkids)
    {
        return toAjax(screeningKeyService.deleteScreeningKeyByIds(pkids));
    }
}
